//
//  YZSwineryListCell.m
//  VET
//
//  Created by 刘文靖 on 2018/7/18.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZSwineryListCell.h"
#import "YZSwineryModel.h"
#import "YZAutoItemModel.h"
#import "YZDashLineView.h"
@interface YZSwineryListCell()
@property (nonatomic, weak) UILabel *batchNoLabel; ///<批次号
@property (nonatomic, weak) UIButton *manageBtn; ///<管理按钮
@property (nonatomic, weak) UILabel *herdClassLabel; ///<批次分类
@property (nonatomic, weak) UILabel *realQtyLabel; ///<存栏头数
@property (nonatomic, weak) UILabel *herdBirthdateLabel; ///<生长日龄
@property (nonatomic, weak) UILabel *herdStateLabel; ///<当前状态
@end
@implementation YZSwineryListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.contentView.backgroundColor = kColorWithHex(0xf5f5f5);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *mainView = [[UIView alloc] init];
        mainView.layer.contentsGravity = kCAGravityResize;
        mainView.layer.contents = (__bridge id)[UIImage imageNamed:@"card_background"].CGImage;
        [self.contentView addSubview:mainView];
        [mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.offset(12);
            make.bottom.offset(0);
            make.right.offset(-12);
        }];
//        YZDashLineView *dashLineView = [[YZDashLineView alloc] initWithFrame:CGRectMake(25, 68, kScreenWidth - 74, 1)];
//        dashLineView.backgroundColor = kColorWithHex(0xE0E0E0);
//        [mainView addSubview:dashLineView];
        ///<批次号
        UILabel *batchNoLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x434343);
            label.font = [UIFont fontWithName:@"SFCompactDisplay-Bold" size:18];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(18);
                make.left.offset(26);
                make.height.mas_equalTo(18);
            }];
            label;
        });
        self.batchNoLabel = batchNoLabel;
        
        UILabel *batchDescLabel = [[UILabel alloc] init];
        batchDescLabel.text = @"批次号";
        batchDescLabel.textColor = kColorWithHex(0x9B9B9B);
        batchDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
        [mainView addSubview:batchDescLabel];
        [batchDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(batchNoLabel.mas_bottom).offset(6);
            make.left.mas_equalTo(batchNoLabel);
        }];
        
        ///<管理按钮
        UIButton *manageBtn = ({
            UIButton *btn = [[UIButton alloc] init];
            [btn setTitle:@"管理" forState:UIControlStateNormal];
            [btn setTitleColor:kColorWithHex(0x32BE60) forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-25);
                make.top.offset(25);
            }];
            btn;
        });
        self.manageBtn = manageBtn;
        
        ///<批次分类
        UILabel *herdClassDescLabel = [[UILabel alloc] init];
        herdClassDescLabel.text = @"批次分类";
        herdClassDescLabel.textColor = kColorWithHex(0x9B9B9B);
        herdClassDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:herdClassDescLabel];
        [herdClassDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(86);
            make.left.mas_equalTo(batchNoLabel);
        }];
        
        UILabel *herdClassLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(herdClassDescLabel.mas_right).offset(5);
                make.top.mas_equalTo(herdClassDescLabel);
            }];
            label;
        });
        self.herdClassLabel = herdClassLabel;
        
        ///<存栏头数
        UILabel *realQtyLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-76);
                make.top.mas_equalTo(herdClassLabel);
            }];
            label;
        });
        self.realQtyLabel = realQtyLabel;
        
        UILabel *realQtyDescLabel = [[UILabel alloc] init];
        realQtyDescLabel.text = @"存栏头数";
        realQtyDescLabel.textColor = kColorWithHex(0x9B9B9B);
        realQtyDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:realQtyDescLabel];
        [realQtyDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(realQtyLabel);
            make.right.mas_equalTo(realQtyLabel.mas_left).offset(-5);
        }];
        
        ///<生长日龄
        UILabel *herdBirthdateDscLabel = [[UILabel alloc] init];
        herdBirthdateDscLabel.text = @"生长日龄";
        herdBirthdateDscLabel.textColor = kColorWithHex(0x9B9B9B);
        herdBirthdateDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:herdBirthdateDscLabel];
        [herdBirthdateDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(herdClassDescLabel.mas_bottom).offset(12);
            make.left.mas_equalTo(herdClassDescLabel);
        }];
        
        UILabel *herdBirthdateLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(herdBirthdateDscLabel.mas_right).offset(5);
                make.top.mas_equalTo(herdBirthdateDscLabel);
            }];
            label;
        });
        self.herdBirthdateLabel = herdBirthdateLabel;
        
        ///<当前状态
        UILabel *herdStateDscLabel = [[UILabel alloc] init];
        herdStateDscLabel.text = @"当前状态";
        herdStateDscLabel.textColor = kColorWithHex(0x9B9B9B);
        herdStateDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:herdStateDscLabel];
        [herdStateDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(herdBirthdateDscLabel);
            make.left.mas_equalTo(realQtyDescLabel);
        }];
        
        UILabel *herdStateLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(herdStateDscLabel.mas_right).offset(5);
                make.top.mas_equalTo(herdStateDscLabel);
            }];
            label;
        });
        self.herdStateLabel = herdStateLabel;
        
        @weakify(self)
        [[self.manageBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            if (self.delegate && [self.delegate respondsToSelector:@selector(cellDidClickManage:)]) {
                [self.delegate cellDidClickManage:self];
            }
        }];
        
    }
    return self;
}

- (void)setModel:(YZSwineryModel *)model{
    _model = model;
    self.batchNoLabel.text = model.batchNo;
    self.herdClassLabel.text = model.herdClass.itemValue?:@"未确定";
    self.realQtyLabel.text = [NSString stringWithFormat:@"%ld",(long)model.realQty];
    self.herdBirthdateLabel.text = model.herdBirthdateStr;
    
    if (model.isFinished) {
        self.herdStateLabel.text = @"结批";
    } else {
        self.herdStateLabel.text = model.herdState.itemValue;
    }
    
}

@end
